%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This code generates the Figure 4 for "Self-Fulfilling Prophecies, 
% Quasi-Non-Ergodicity & Wealth Inequality by
% Jean-Philippe Bouchaud and Roger E. A. Farmer This version by R.E.A.
% Farmer:  August 2 2022
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear;

delt= 3.9*10^(-4);
alpha = 1;  % Change this to check robustness
lambda = sqrt(delt/alpha);

p = linspace(0,1);

figure(4);
plot(p,lambda*abs(p-1/2),'-b','LineWidth',2)
hold on
plot(p,sqrt(lambda/2*p.*(1-p)),'--r','LineWidth',2)
hold off

legend('Absolute Bias of R','Standard Error of R','FontSize',16,...
    'location','southoutside');
xlabel('Probability s=1','FontSize',16)

ylim([0,0.052]);